package com.pig4cloud.pig.djjk.service.immi;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.pig4cloud.pig.djjk.config.FaceApiConfig;
import com.pig4cloud.pig.djjk.domain.po.TraceResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.logging.Logger;

import static com.pig4cloud.pig.djjk.utils.HttpUtil.postRequest;


/**
 * @className: TraceService
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2025/6/7
 **/

@Service
public class TraceService {

    Logger log = Logger.getLogger(FaceApiService.class.getName());

    @Autowired
	FaceApiConfig faceApiConfig;

    //获取人员轨迹
    public String getTracePic(String base64Img, List<List<Integer>> points) {

        try {

            JSONObject json = new JSONObject();

            json.put("image", base64Img);
            json.put("points", points);

            // Create HTTP POST request
            log.info("请求地址:"+faceApiConfig.getTraceUrl());
            String responseString = postRequest(faceApiConfig.getTraceUrl(), json.toString());
            if (StringUtils.isNotEmpty(responseString)) {
                TraceResponse traceResponse = JSON.parseObject(
                        responseString,
                        new TypeReference<TraceResponse>() {
                        }
                );
                if (StringUtils.isNotEmpty(traceResponse.getImage())) {
                    return traceResponse.getImage();
                } else {
                    log.info("获取人员轨迹失败");
                    return null;
                }
            }
            return null;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
